package InetAdress;

import javax.sound.sampled.Line;
import java.io.*;
import java.net.InetAddress;


import java.net.Socket;

public class outputAdress {
    public static void main(String[] args) throws IOException {
        //链接服务端IP，端口
        Socket socket=new Socket(InetAddress.getLocalHost(),9999);
        System.out.println(socket.getClass());

        //输入字符
        OutputStream outputStream= socket.getOutputStream();
        //outputStream.write("hello,socket".getBytes())
        BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(outputStream));
        bufferedWriter.write("hello,server");
        bufferedWriter.newLine();//表示写入结束
        bufferedWriter.flush();//如果使用字符流需要使用手动刷新，不然不会写入数字通道

        //读取字符并显示
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(socket.getInputStream()));
        System.out.println(bufferedReader.readLine());
        bufferedReader.readLine();
        //关闭流或socket
        bufferedReader.close();
        bufferedWriter.close();
        socket.close();
        outputStream.close();
    }
}
